
//
//  AssignViewController.m
//  atXiaoGeBClient
//
//  Created by Linyu Niu on 23/04/2018.
//  Copyright © 2018 Linyu Niu. All rights reserved.
//

#import "AssignViewController.h"

@interface AssignViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * assignTableView;
}
@end

@implementation AssignViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView * bgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"background"]];
    
    bgView.frame = CGRectMake(0, 0, bgView.image.size.width, bgView.image.size.height);
    [self.view addSubview:bgView];
    
    __weak AssignViewController * weakSelf = self;
    UIView * navView = [[CTMediator sharedInstance] navgationHeadViewInTargetView:self.view params:[NSDictionary dictionaryWithObjectsAndKeys:@"派件",@"title", nil] leftAction:^(UIButton * sender){
        
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } rightAction:nil];
    navView.backgroundColor = [UIColor clearColor];
    assignTableView = [self addTableViewInView:self.view frame:CGRectMake(0, navView.frame.origin.y + navView.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - (navView.frame.origin.y + navView.frame.size.height)) delegateAndDataSource:self];
    assignTableView.scrollEnabled = NO;
    assignTableView.backgroundColor = [UIColor colorWithRed:233.0 / 255.0 green:233.0 / 255.0 blue:233.0 / 255.0 alpha:1.0];
}

-(void)assignScan{
    [self startLoadingView:self.view];
    
    __weak AssignViewController * weakSelf = self;
    [[CTMediator sharedInstance] netSendAvailable:^(NSDictionary *dic){
        [weakSelf stopLoadingView:weakSelf.view needShowMsg:YES result:dic];
        BOOL hasPermission = [[[dic objectForKey:@"data"] objectForKey:@"available"] boolValue];
        if (hasPermission) {
            
        }else{
            UIViewController * controller = [[CTMediator sharedInstance] noAuthController];
            [weakSelf.navigationController pushViewController:controller animated:YES];
        }
    }];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ElementTableViewCell * cell = [[ElementTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    if ([indexPath section] == 0) {
        cell.backgroundColor = [UIColor clearColor];
        UIButton * assignScanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [assignScanBtn addTarget:self action:@selector(assignScan) forControlEvents:UIControlEventTouchUpInside];
        assignScanBtn.frame = CGRectMake(0, 0, tableView.frame.size.width / 2, 100);
        assignScanBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [assignScanBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [assignScanBtn setTitle:@"派件扫描" forState:UIControlStateNormal];
        [cell addSubview:assignScanBtn];
        
        UIButton * receivedScanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        receivedScanBtn.frame = CGRectMake(assignScanBtn.frame.size.width, 0, assignScanBtn.frame.size.width, assignScanBtn.frame.size.height);
        receivedScanBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [receivedScanBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [receivedScanBtn setTitle:@"签收扫描" forState:UIControlStateNormal];
        [cell addSubview:receivedScanBtn];
        
        cell.cellHeight = assignScanBtn.frame.size.height + assignScanBtn.frame.origin.y * 2;
        
        UIImageView * bgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"background"]];
        
        bgView.frame = CGRectMake(0, 0, tableView.frame.size.width, cell.cellHeight);
        [cell addSubview:bgView];
        [cell sendSubviewToBack:bgView];
    }else if([indexPath section] == 1){
        cell.cellHeight = 50;
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.textLabel.textColor = UIColorFromRGB(0x333333);
        if ([indexPath row] == 0) {
            cell.textLabel.text = @"发短信";
        }else if([indexPath row] == 1){
            cell.textLabel.text = @"打电话";
        }else if([indexPath row] == 2){
            cell.textLabel.text = @"问题件";
        }
        if ([indexPath row] != 0) {
            UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 1.0)];
            lineView.backgroundColor = UIColorFromRGB(0xBCBCBC);
            [cell addSubview:lineView];
        }
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ElementTableViewCell * cell = (ElementTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.cellHeight;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else if(section == 1){
        return 3;
    }
    return 0 ;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        return 15;
    }
    return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 15)];
    return v;
}

@end
